#include <gtest/gtest.h>
#include "core/http/http_response.h"

using namespace aliyun;

TEST(core_http, HttpResponse) {
  HttpResponse response;

  size_t body_length;
  const char* body = (const char*)response.GetBody(body_length);
  ASSERT_EQ(body, (void*)0);
  ASSERT_EQ(body_length, (size_t)0);

  const char *test_body = "test body";
  size_t test_body_length = strlen(test_body)+1; // include '\0'
  ASSERT_TRUE(response.SetBody((const unsigned char*)test_body, test_body_length));
  body = (const char*)response.GetBody(body_length);
  ASSERT_STREQ(body, test_body);
  ASSERT_EQ(body_length, test_body_length);

  test_body = "test body";
  test_body_length = strlen(test_body);
  ASSERT_TRUE(response.SetBody((const unsigned char*)test_body, test_body_length));
  ASSERT_TRUE(response.AppendBody((const unsigned char*)test_body, test_body_length+1)); // include '\0'
  body = (const char*)response.GetBody(body_length);
  ASSERT_STREQ(body, "test bodytest body");
  ASSERT_EQ(body_length, test_body_length+test_body_length+1);// include '\0'

  response.SetStatus(199);
  ASSERT_EQ(response.GetStatus(), 199);
  ASSERT_FALSE(response.IsSuccess());
  response.SetStatus(200);
  ASSERT_EQ(response.GetStatus(), 200);
  ASSERT_TRUE(response.IsSuccess());
  response.SetStatus(300);
  ASSERT_EQ(response.GetStatus(), 300);
  ASSERT_FALSE(response.IsSuccess());
}


// end of file
